// Device/pages/Bind/Verify/components/glucometer-component/index.js
Component({

    /**
     * 组件的属性列表
     */
    properties: {
        componentData: {
            default: {},
            type: Object
        }
    },
    observers: {
        'componentData': function(value) {
            if(value) {
                this.setData({
                    ...value
                })
            }
        }
    },

    /**
     * 组件的初始数据
     */
    data: {
        collapseActive: [],
        glu_min_self: 3.9,
        glu_max_self: 6.1,
        pbg_min_self: 3.9,
        pbg_max_self: 7.8,
        glu_min_mate: 3.9,
        glu_max_mate: 6.1,
        pbg_min_mate: 3.9,
        pbg_max_mate: 7.8,
        glu_min_sons: 3.9,
        glu_max_sons: 6.1,
        pbg_min_sons: 3.9,
        pbg_max_sons: 7.8,
        glu_min_other: 3.9,
        glu_max_other: 6.1,
        pbg_min_other: 3.9,
        pbg_max_other: 7.8
    },

    /**
     * 组件的方法列表
     */
    methods: {
        onCollapseChange(e) {
            this.setData({
                collapseActive: e.detail
            })
        },
        onSlideChange(e) {
            const {
                type
            } = e.currentTarget.dataset;
            if (['pulse_self', 'pulse_mate', 'pulse_sons', 'pulse_other', 'glu_self', 'pbg_self', 'glu_mate', 'pbg_mate', 'glu_sons', 'pbg_sons', 'glu_other', 'pbg_other'].includes(type)) {
                this.setData({
                    [`${type.split('_').join('_min_')}`]: e.detail[0],
                    [`${type.split('_').join('_max_')}`]: e.detail[1]
                })
            } else {
                this.setData({
                    [`${type}`]: e.detail
                })
            }
        },
        onNavigate() {
            this.triggerEvent('navigate')
        },
    }
})